﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using Microsoft.Kinect;
using Microsoft.Win32;
using Kinect.Toolbox;
using Kinect.Toolbox.Gestures;
using Kinect.Toolbox.Voice;
using System.Threading;
using System.Threading.Tasks;
using Kinect.Toolbox.Record;
using Microsoft.Speech.AudioFormat;
using Microsoft.Speech.Recognition;
using Kinectver1._0.CadObject;

namespace Kinectver1._0.openScad
{
    public class openSCAD
    {
        public string cmdOutputted { get; set; }
        public string path { get; set; }

        public ProcessStartInfo runSCADinfo;
        //constructor
        public openSCAD()
        {
            //this is where openscad should be installed on most systems
            runSCADinfo = new ProcessStartInfo(@"C:\Program Files (x86)\OpenSCAD\openscad.exe");

            //lets hide the windows
            runSCADinfo.CreateNoWindow = true; //this can also change
            runSCADinfo.WindowStyle = ProcessWindowStyle.Normal;


            //this will start it
            Process.Start(runSCADinfo);
            
        }
        //opening .OFF file and loading into open gl
        
        private void make_square(double l, double h)
        {
            StreamWriter sw = new StreamWriter(@"C:\openSCADfile.scad");
            string length = l.ToString();
            string height = h.ToString();
            string output = "square([" + length + " , " + height + "], center = true);";
//          sw.WriteLine("square([10,8], center = true);\n");
            sw.WriteLine(output);
            sw.Close();
        }

        private void make_circle(double r)
        {
            StreamWriter sw = new StreamWriter(@"C:\openSCADfile.scad");
            string radius = r.ToString();
            string output = "circle([" + radius +"]);";
            sw.WriteLine(output);
//          sw.WriteLine("circle([3]);\n");
            sw.Close();

        }

        private void translate(double l, double h)
        {
            StreamWriter sw = new StreamWriter(@"C:\openSCADfile.scad");
            sw.WriteLine("translate([2,2,0]) {circle(5);}");
            sw.Close();
        }

        private void difference()
        {
            StreamWriter sw = new StreamWriter(@"C:\openSCADfile.scad");
            sw.WriteLine("difference() {square([25,20], center=true); circle(5);}");
            sw.Close();
        }

        private void clear()
        {
            StreamWriter sw = new StreamWriter(@"C:\openSCADfile.scad");

            //          TextWriter writer = new StreamWriter(stream);
            sw.WriteLine("");
            //sw.WriteLine("");
            //FileStream stream = new FileStream( @"C:\test.openSCADfile.scad", FileMode.Create );

        }
/*
        private void if_check()
        {
            if cadObject.Equals() == Type <Square?>
            {
                make_square(20,15);
            }
*/ 
        /*
        private void openscadSystem()
        {
            system("openscad -o my_modelCyl.off my_modelCyl.scad");
            return 0;
        }
        */
    }
}
